package com.yidiandao.business.ui.main.usercenter;

import android.graphics.Color;
import android.support.v4.widget.NestedScrollView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.v5kf.client.lib.V5ClientAgent;
import com.yidiandao.business.R;
import com.yidiandao.business.base.BaseEventFragment;
import com.yidiandao.business.constant.Preferences;
import com.yidiandao.business.data.bean.User;
import com.yidiandao.business.data.event.RefreshUserCenterPointEvent;
import com.yidiandao.business.ui.addressabout.addressmanager.AddressManagerActivity;
import com.yidiandao.business.ui.agents.AgentsActivity;
import com.yidiandao.business.ui.assetabout.coupon.CouponActivity;
import com.yidiandao.business.ui.assetabout.redpacket.RedPacketActivity;
import com.yidiandao.business.ui.bindabout.bindqrcode.BindQrCodeActivity;
import com.yidiandao.business.ui.browsing.BrowsingHistoryActivity;
import com.yidiandao.business.ui.collect.CollectActivity;
import com.yidiandao.business.ui.userabout.wanttobuy.userposted.UserPostedWantToBuyActivity;
import com.yidiandao.business.ui.messageabout.MessageActivity;
import com.yidiandao.business.ui.orderabout.activeorder.ActiveOrderActivity;
import com.yidiandao.business.ui.orderabout.exchange.ExchangeActivity;
import com.yidiandao.business.ui.orderabout.order.OrderActivity;
import com.yidiandao.business.ui.service.ServiceActivity;
import com.yidiandao.business.ui.url.UrlActivity;
import com.yidiandao.business.ui.userabout.invoicemanager.InvoiceManagerActivity;
import com.yidiandao.business.ui.userabout.setting.SettingActivity;
import com.yidiandao.business.ui.userabout.user.UserActivity;
import com.yidiandao.business.ui.widget.dialog.LoadingDialog;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.PreferenceUtils;
import com.yidiandao.business.utils.RealmUtils;
import com.yidiandao.business.utils.UIUtils;
import com.yidiandao.business.utils.UmengUtils;
import com.yidiandao.business.utils.UrlUtils;
import com.yidiandao.business.utils.V5ChartUtils;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import io.realm.Realm;

/**
 * 我的
 */
public class UserCenterFragment extends BaseEventFragment
        implements UserCenterContract.View, View.OnClickListener {

    public static final String TAG = UserCenterFragment.class.getSimpleName();

    private UserCenterContract.Presenter mPresenter;

    private ImageView mIvSetting;

    private TextView mTvTittle;

    private ImageView mIvAvatar;

    private RelativeLayout mRlUserCenterAllOrder;

    private LinearLayout mLlUserCenterUnPay,
            mLlUserCenterUnSend,
            mLlUserCenterUnTakeGoods,
            mLlUserCenterExchange;

    private RelativeLayout mLlUserCenterDelivery;

    private TextView mIvUserCenterUsername;

    private LinearLayout mLlUserCenterCollect;

    private TextView mTvUserCenterCollectNum;

    private RelativeLayout mLlUserCenterWantToBuy;

    private TextView mTvUserCenterWanttobuyNum;

    private LinearLayout mLlUserCenterBrowsing;

    private TextView mLlUserCenterBrowsingNum;

    private RelativeLayout mLlUserCenterHeadBg;

    private RelativeLayout mRlUserCenterInvent;

    private RelativeLayout mRlUserCenterServiceAndFeedback;

    private ImageView mIvUserCenterSettingGray;

    private LinearLayout mLlytBalance, mLlytCoupon, mLlytRedPaper, mLlytIntegral;

    private TextView mTvUnPayNum;

    private TextView mTvUnSendNum;

    private TextView mTvUnFinishNum;

    private TextView mTvMoney;

    private TextView mTvCouponNum;

    private TextView mTvRedPaper;

    private TextView mTvNewMessageCount;

    private ImageView mIvNewOfferMessage;

    private RelativeLayout mRlToolbar;

    private RelativeLayout mRlytSetting;

    private TextView mTvExchangeNum;

    private ImageView mIvNewAgentMessage;

    private LoadingDialog mLoadingDialog;

    private NestedScrollView mScrollView;

    private int scrollHeight;

    private boolean mIsSigned;

    private RelativeLayout mRlUserCenterNews,
            mRlUserCenterAddress,
            mRlUserCenterServer,
            mRlUserCenterInvoice;

    private LinearLayout mLlytCard;

    private TextView mTvCard;

    private TextView mTvIntegral;

    private View mViewLine;

    private RelativeLayout mRlZxing;

    private RelativeLayout mRlUserActive;

    public static UserCenterFragment getInstance() {
        return new UserCenterFragment();
    }

    @Override
    public void onResume() {
        super.onResume();
        initUserCenterUI();
    }

    @Override
    protected void initViews() {
        mLoadingDialog = new LoadingDialog(mActivity);

        mScrollView = (NestedScrollView) mRootView.findViewById(R.id.scrollView);

        //设置
        mIvSetting = (ImageView) mRootView.findViewById(R.id.iv_user_center_setting);
        mIvUserCenterSettingGray =
                (ImageView) mRootView.findViewById(R.id.iv_user_center_setting_gray);
        //标题
        mRlToolbar = (RelativeLayout) mRootView.findViewById(R.id.rl_toolbar);
        mTvTittle = (TextView) mRootView.findViewById(R.id.tv_user_center_title);
        mViewLine = mRootView.findViewById(R.id.view_line);

        //头像
        mIvAvatar = (ImageView) mRootView.findViewById(R.id.iv_user_center_avatar);


        mRlUserActive = (RelativeLayout) mRootView.findViewById(R.id.rl_user_active);//活动订单

        mLlUserCenterDelivery =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_delivery); //我是代理商
        mRlUserCenterAllOrder =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_all_order); //全部订单
        mLlUserCenterUnPay =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_un_pay); //未付款
        mLlUserCenterUnSend =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_un_send); //未发货
        mLlUserCenterUnTakeGoods =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_un_take_goods); //未收货
        mLlUserCenterExchange =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_exchange); //退换货

        mIvUserCenterUsername =
                (TextView) mRootView.findViewById(R.id.iv_user_center_username); //用户名
        mRlUserCenterAddress =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_address); //设置收货地址
        mLlUserCenterCollect =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_collect); //我的收藏
        mTvUserCenterCollectNum =
                (TextView) mRootView.findViewById(R.id.tv_user_center_collect_num); //我的收藏个数
        mLlUserCenterWantToBuy =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_want_to_buy); //求购信息
        mLlUserCenterBrowsing =
                (LinearLayout) mRootView.findViewById(R.id.ll_user_center_browsing); //浏览历史
        mLlUserCenterBrowsingNum =
                (TextView) mRootView.findViewById(R.id.ll_user_center_browsing_num); //浏览历史个数

        mTvUnPayNum = (TextView) mRootView.findViewById(R.id.tv_unPay_num); //未付款个数
        mTvUnSendNum = (TextView) mRootView.findViewById(R.id.tv_un_send_num); //未配送个数
        mTvUnFinishNum = (TextView) mRootView.findViewById(R.id.tv_un_finish_num); //未完成个数
        mTvExchangeNum = (TextView) mRootView.findViewById(R.id.tv_exchange_num); //退换货个数

        mTvMoney = (TextView) mRootView.findViewById(R.id.tv_money); //余额
        mTvCouponNum = (TextView) mRootView.findViewById(R.id.tv_coupon_num); //优惠券个数
        mTvRedPaper = (TextView) mRootView.findViewById(R.id.tv_bonus); //红包个数
        mLlytCard = (LinearLayout) mRootView.findViewById(R.id.llyt_card);
        mTvCard = (TextView) mRootView.findViewById(R.id.tv_card); //银行卡

        mLlytIntegral = (LinearLayout) mRootView.findViewById(R.id.llyt_integral);
        mTvIntegral = (TextView) mRootView.findViewById(R.id.tv_integral); //积分

        mLlUserCenterHeadBg = (RelativeLayout) mRootView.findViewById(R.id.ll_user_center_head_bg);

        mRlUserCenterInvent =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_invent); //邀请好友
        mRlUserCenterServiceAndFeedback =
                (RelativeLayout)
                        mRootView.findViewById(R.id.rl_user_center_serviceAndFeedback); //服务于反馈

        mRlUserCenterNews = (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_news); //消息
        mRlUserCenterAddress =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_address); //地址管理
        mRlUserCenterServer =
                (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_server); //在线客服

        mRlZxing = (RelativeLayout) mRootView.findViewById(R.id.rl_zxing);//绑定客户关系

        mRlUserCenterInvoice = (RelativeLayout) mRootView.findViewById(R.id.rl_user_center_invoice);

        mLlytBalance = (LinearLayout) mRootView.findViewById(R.id.llyt_balance);
        mLlytCoupon = (LinearLayout) mRootView.findViewById(R.id.llyt_coupon);
        mLlytRedPaper = (LinearLayout) mRootView.findViewById(R.id.llyt_red_paper);
        mLlytIntegral = (LinearLayout) mRootView.findViewById(R.id.llyt_integral);

        // 新的消息
        mTvNewMessageCount = (TextView) mRootView.findViewById(R.id.tv_new_message_count);
        // 新的报价推送消息
        mIvNewOfferMessage = (ImageView) mRootView.findViewById(R.id.iv_new_offer_message);
        // 我是代理商有新消息时的提示
        mIvNewAgentMessage = (ImageView) mRootView.findViewById(R.id.iv_new_agent_message);

        mRlytSetting = (RelativeLayout) mRootView.findViewById(R.id.rlyt_setting);

        initEvent();
    }

    private void initEvent() {
        mIvAvatar.setOnClickListener(this);
        mLlUserCenterUnPay.setOnClickListener(this);
        mRlUserCenterAllOrder.setOnClickListener(this);
        mLlUserCenterUnSend.setOnClickListener(this);
        mLlUserCenterUnTakeGoods.setOnClickListener(this);
        mLlUserCenterExchange.setOnClickListener(this);
        mLlUserCenterDelivery.setOnClickListener(this);
        mLlUserCenterCollect.setOnClickListener(this);
        mLlUserCenterWantToBuy.setOnClickListener(this);
        mLlUserCenterBrowsing.setOnClickListener(this);
        mRlUserCenterServiceAndFeedback.setOnClickListener(this);
        mRlUserCenterAddress.setOnClickListener(this);
        mRlUserCenterInvoice.setOnClickListener(this);
        mLlytBalance.setOnClickListener(this);
        mLlytCoupon.setOnClickListener(this);
        mLlytRedPaper.setOnClickListener(this);
        mLlytIntegral.setOnClickListener(this);
        mRlUserCenterInvent.setOnClickListener(this);
        mRlUserCenterAddress.setOnClickListener(this);
        mRlUserCenterServer.setOnClickListener(this);
        mLlytCard.setOnClickListener(this);
        mLlytIntegral.setOnClickListener(this);
        mRlZxing.setOnClickListener(this);
        mRlUserActive.setOnClickListener(this);

        mLlUserCenterHeadBg
                .getViewTreeObserver()
                .addOnGlobalLayoutListener(
                        new ViewTreeObserver.OnGlobalLayoutListener() {
                            @Override
                            public void onGlobalLayout() {
                                scrollHeight =
                                        mLlUserCenterHeadBg.getHeight() - mRlToolbar.getHeight();
                                mLlUserCenterHeadBg
                                        .getViewTreeObserver()
                                        .removeGlobalOnLayoutListener(this);
                            }
                        });
        mScrollView.setOnScrollChangeListener(
                new NestedScrollView.OnScrollChangeListener() {
                    @Override
                    public void onScrollChange(
                            NestedScrollView v,
                            int scrollX,
                            int scrollY,
                            int oldScrollX,
                            int oldScrollY) {
                        if (scrollHeight != 0) {
                            int alpha;
                            if (scrollY != 0) {
                                alpha = scrollY * 255 / scrollHeight;
                                if (alpha > 255)
                                    alpha = 255;
                            } else {
                                alpha = 0;
                            }
                            mRlToolbar.setBackgroundColor(Color.argb(alpha, 255, 255, 255));
                            mViewLine.setBackgroundColor(Color.argb(alpha, 235, 235, 235));
                            mTvTittle.setTextColor(Color.argb(alpha, 63, 38, 49));
                            mIvUserCenterSettingGray.setAlpha(alpha);
                            mIvSetting.setAlpha(255 - alpha);
                        }
                    }
                });

        mRlytSetting.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SettingActivity.actionStart(mActivity);
                    }
                });
        mRlUserCenterServiceAndFeedback.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //服务与反馈
                        UmengUtils.onEvent(mActivity, R.string.umeng_user_center_server);
                        ServiceActivity.actionStart(mActivity);
                    }
                });
        mRlUserCenterServer.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //在线客服
                        UmengUtils.onEvent(mActivity, R.string.umeng_online_server);
                        V5ChartUtils.toV5ChartActivity();
                    }
                });
        mRlUserCenterNews.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //消息
                        UmengUtils.onEvent(mActivity, R.string.umeng_user_center_message);
                        MessageActivity.actionStart(mActivity);
                    }
                });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_user_center;
    }

    @Override
    public void setPresenter(UserCenterContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return TAG;
    }

    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }

    @Override
    public void setNewOfferMessageVisibility(boolean visibility) {
        mIvNewOfferMessage.setVisibility(visibility ? View.VISIBLE : View.GONE);
    }

    @Override
    public void setNewAgentPushVisibility(boolean visibility) {
        mIvNewAgentMessage.setVisibility(visibility ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_user_center_avatar:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_avatar);
                //去往个人中心
                UserActivity.actionStart(mActivity);
                break;
            case R.id.rl_user_center_address:
                //去往设置地址
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_address);
                AddressManagerActivity.actionStart(mActivity);
                break;
            case R.id.rl_user_center_all_order:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_order);
                //全部订单
                OrderActivity.actionStart(mActivity, 0);
                break;
            case R.id.ll_user_center_un_pay:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_order);
                //未支付
                OrderActivity.actionStart(mActivity, 1);
                break;
            case R.id.ll_user_center_un_send:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_order);
                //未发货
                OrderActivity.actionStart(mActivity, 2);
                break;
            case R.id.ll_user_center_un_take_goods:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_order);
                //未收货
                OrderActivity.actionStart(mActivity, 3);
                break;
            case R.id.rl_user_center_delivery:
                //我是代理商
                UmengUtils.onEvent(mActivity, R.string.umeng_agents);
                setNewAgentPushVisibility(false);
                mPresenter.setHasNewAgentPushMessage(false);
                AgentsActivity.actionStart(mActivity, false);
                break;
            case R.id.rl_user_center_want_to_buy:
                UmengUtils.onEvent(mActivity, R.string.umeng_ask_to_buy);
                //求购信息
                setNewOfferMessageVisibility(false);
                mPresenter.setHasNewOfferMessage(false);
                UserPostedWantToBuyActivity.actionStart(mActivity);
                break;
            case R.id.ll_user_center_browsing:
                //浏览历史
                BrowsingHistoryActivity.actionStart(mActivity);
                break;

            case R.id.ll_user_center_collect:
                //收藏
                CollectActivity.actionStart(mActivity);
                break;
            case R.id.ll_user_center_exchange:
                //退换货
                ExchangeActivity.actionStart(mActivity);
                break;
            case R.id.llyt_balance:
                //金融
                showToast(UIUtils.getString(R.string.developing_hint));
                // BalanceActivity.actionStart(mActivity);
                break;
            case R.id.llyt_card:
                //银行卡
                showToast(UIUtils.getString(R.string.developing_hint));
                //                     BankCardActivity.actionStart(mActivity);
                break;
            case R.id.llyt_integral:
                //积分
                showToast(UIUtils.getString(R.string.developing_hint));
                // BalanceActivity.actionStart(mActivity);
                break;
            case R.id.llyt_coupon:
                // 优惠券
                UmengUtils.onEvent(mActivity, R.string.umeng_assets_coupon);
                CouponActivity.actionStart(mActivity);
                break;
            case R.id.llyt_red_paper:
                // 红包
                UmengUtils.onEvent(mActivity, R.string.umeng_assets_red);
                RedPacketActivity.actionStart(mActivity);
                break;
            case R.id.rl_user_center_invent:
                UmengUtils.onEvent(mActivity, R.string.umeng_user_center_invite);
                UrlActivity.actionStart(mActivity, UrlUtils.getTrulyUrl("Activity/invitation"));
                break;
            case R.id.rl_user_center_invoice:
                InvoiceManagerActivity.actionStart(mActivity);
                break;
            case R.id.rl_zxing:
                //绑定客户关系
                BindQrCodeActivity.actionStart(mActivity);
                break;
            case R.id.rl_user_active:
                //活动订单
                ActiveOrderActivity.actionStart(mActivity);
                break;
        }
    }

    /**
     * 未登录时的数据和view
     */
    public void setUnLoginDataAndView() {
        mIvUserCenterUsername.setText(UIUtils.getString(R.string.user_center_noLogin));
        mIvAvatar.setImageResource(R.mipmap.ic_avatar_normal);
        mLlUserCenterDelivery.setVisibility(View.GONE); //我是代理商
        mTvUnPayNum.setVisibility(View.GONE); //未付款个数
        mTvUnSendNum.setVisibility(View.GONE); //为配送个数
        mTvUnFinishNum.setVisibility(View.GONE); //为完成个数
        mTvExchangeNum.setVisibility(View.GONE); //退换货个数
        mTvMoney.setVisibility(View.GONE); //资金
        mTvCouponNum.setVisibility(View.GONE); //优惠券个数
        mTvRedPaper.setVisibility(View.GONE); //红包个数
        mTvCard.setVisibility(View.GONE); //银行卡
        mTvIntegral.setVisibility(View.GONE); //积分
        mTvNewMessageCount.setVisibility(View.GONE); // 消息-未读数量
    }

    /**
     * 获取realm对象
     *
     * @return ream对象
     */
    @Override
    public Realm getRealm() {
        return RealmUtils.getHistoryRealm(mActivity);
    }

    /**
     * 登录时的数据和view
     */
    public void setSignedDataAndView() {
        mIvUserCenterUsername.setVisibility(View.VISIBLE);
        mTvMoney.setVisibility(View.VISIBLE); //资金
        mTvCouponNum.setVisibility(View.VISIBLE); //优惠券个数
        mTvRedPaper.setVisibility(View.VISIBLE); //红包个数
        mTvCard.setVisibility(View.VISIBLE); //银行卡
        mTvIntegral.setVisibility(View.VISIBLE); //积分
    }

    @Override
    public void onPause() {
        super.onPause();
        if (mIsSigned)
            mPresenter.destroy();
    }

    /**
     * 浏览历史的格式
     */
    @Override
    public void setBrowsingHistoryNum(int num) {
        mLlUserCenterBrowsingNum.setText(num + "");
    }

    @Override
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(RefreshUserCenterPointEvent event) {
        // 此处需要注意，只有为true时才更新标记，因为这个事件只有接收到推送之后才会发出
        // 接收到推送时会判定具体是哪一种类型的推送
        if (event.isNewAgentMessage()) {
            setNewAgentPushVisibility(event.isNewAgentMessage());
        }
        if (event.isNewOfferMessage()) {
            setNewOfferMessageVisibility(event.isNewOfferMessage());
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        V5ClientAgent.getInstance().setChatActivityListener(null);
    }

    private void initUserCenterUI() {
        mIsSigned =
                !PreferenceUtils.STRING_DEFAULT.equals(
                        PreferenceUtils.getToken(mActivity)); //判断是否已经登录
        if (mIsSigned) {
            //若是已经登录就获取数据
            mPresenter.start();
            setSignedDataAndView();
        } else {
            //未登录
            setUnLoginDataAndView();
        }

        // 根据是否有新推送显示 红点
        setNewAgentPushVisibility(mPresenter.hasNewAgentPushMessage());
        setNewOfferMessageVisibility(mPresenter.hasNewOfferMessage());
    }

    @Override
    public void notifyDataChanged() {
        initUserCenterUI();
    }

    @Override
    public void showDialog() {
        mLoadingDialog.show();
    }

    @Override
    public void disMissDialog() {
        mLoadingDialog.dismiss();
    }

    @Override
    public void setUserInfo(User user) {
        //头像
        ImageLoader.loadAvatar(mActivity, mIvAvatar);
        //昵称
        mIvUserCenterUsername.setText(
                TextUtils.isEmpty(user.getNickName()) ? user.getUserName() : user.getNickName());
        //收藏
        mTvUserCenterCollectNum.setText(user.getCollectionCount() + "");
        //求购
//        mTvUserCenterWanttobuyNum.setText(user.getWantBuyCount() + "");
        //代付款
        mTvUnPayNum.setVisibility(user.getUnpayCount() == 0 ? View.GONE : View.VISIBLE);
        mTvUnPayNum.setText(user.getUnpayCount() > 99 ? "99+" : user.getUnpayCount() + "");
        //代配送
        mTvUnSendNum.setVisibility(user.getUnshipCount() == 0 ? View.GONE : View.VISIBLE);
        mTvUnSendNum.setText(user.getUnshipCount() > 99 ? "99+" : user.getUnshipCount() + "");
        //已发货
        mTvUnFinishNum.setVisibility(user.getUnreceiveCount() == 0 ? View.GONE : View.VISIBLE);
        mTvUnFinishNum.setText(
                user.getUnreceiveCount() > 99 ? "99+" : user.getUnreceiveCount() + "");
        //退换货
        mTvExchangeNum.setVisibility(user.getApplyCount() == 0 ? View.GONE : View.VISIBLE);
        mTvExchangeNum.setText(user.getApplyCount() > 99 ? "99+" : user.getApplyCount() + "");
        //红包
        mTvRedPaper.setText(
                UIUtils.getString(R.string.user_center_redpacket_num, user.getBonusCount() + ""));
        //优惠券
        mTvCouponNum.setText(
                UIUtils.getString(R.string.user_center_coupon_num, user.getFavCount() + ""));
        //金融
        mTvMoney.setText("敬请期待");
        //银行卡
        //        mTvCard.setText( UIUtils.getString(R.string.user_center_coupon_num, user.getFavCount()
        // + ""));
        mTvCard.setText("敬请期待");
        //积分
        mTvIntegral.setText("敬请期待");
        //代理商
        boolean isAgent = user.getIsAgent() == 1;
        PreferenceUtils.setBoolean(mActivity, Preferences.IS_AGENT, isAgent, false);
        mLlUserCenterDelivery.setVisibility(isAgent ? View.VISIBLE : View.GONE);
    }

    @Override
    public void refreshTotalUnReadMessage(int totalUnReadMessageCount) {
        if (totalUnReadMessageCount <= 0) {
            mTvNewMessageCount.setVisibility(View.GONE);
            return;
        }

        mTvNewMessageCount.setVisibility(View.VISIBLE);
        if (totalUnReadMessageCount <= 99) {
            mTvNewMessageCount.setText(totalUnReadMessageCount + "");
            return;
        }

        mTvNewMessageCount.setText(R.string.more_message);
    }
}
